home *** CD-ROM | disk | FTP | other *** search
- Path: god.bel.alcatel.be!usenet
- From: bailleuf@btmaa.bel.alcatel.be (Frank Bailleul)
- Newsgroups: comp.lang.c++
- Subject: Exporting instantiated template classes in windows DLLs
- Date: Tue, 19 Mar 1996 13:23:23 GMT
- Organization: Alcatel Bell
- Message-ID: <4imc8p$3kk@btmpjg.god.bel.alcatel.be>
- NNTP-Posting-Host: 138.203.28.170
- X-Newsreader: Forte Free Agent 1.0.82
-
- I am experimenting with DLLs in windows 95.
- I use the MS Visual C++ 4.0 compiler.
- How can I export an instantiated template class (if that is
- possible ?)
-
- Example :
- --- begin ---
- #define EXPORT __declspec(dllexport)
-
- class EXPORT MyClass {
- ... // dont't care
- };
-
- typedef std::vector<MyClass> MyClassArray;
-
- class EXPORT MyContainer {
- public:
- MyClassArray /* yes, I want to make a copy of the list */
- GetArray() const { return _data; }
- private:
- MyClassArray _data;
- };
- --- end ---
-
- How can I export MyClassArray ?
-
- If I don't export the class, the compiler gives
- warnings, saying that MyClassArray should have
- a DLL interface.
-
- OK, I don't export the class MyClassArray, so the client
- which uses the DLL has to define that class.
-
- Example Client :
- --- begin ---
- typedef std::vector<MyClass*> MyClassArray;
-
- int main() {
- MyContainer cont;
- { // local block
- MyClassArray ar = cont.GetArray();
- } // ar is deleted *
- return 0;
- }
-
- Doing that, the executable client crashes at point *,
- where MyClassArray is destructed.
-
- Could anyone explain me :
- 1. if an instantiated template class can be exported
- and if it can, how to do it ?
- 2. why the program crashed ?
-
-